package org.zoomdev.zoom.dao.adapters.statement;

import org.zoomdev.zoom.dao.adapters.StatementAdapter;

import java.io.ByteArrayInputStream;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class ByteArray2Blob implements StatementAdapter {
    @Override
    public void adapt(PreparedStatement statement, int index, Object value) throws SQLException {
        if (value == null) {
            statement.setObject(index, null);
        } else {
            byte[] bytes = (byte[]) value;
            statement.setBinaryStream(index, new ByteArrayInputStream(bytes), bytes.length);
        }
    }
}
